package com.atguigui.leetcode;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 1704.判断字符串的两半是否相似
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/11/11 9:13
 */
public class P1704DetermineIfStringHalvesAreAlike {
    public static void main(String[] args) {
        Solution solution = new P1704DetermineIfStringHalvesAreAlike().new Solution();
        // TO TEST
        String str = "textbook";
        System.out.println(solution.halvesAreAlike(str));
    }


    class Solution {
        public boolean halvesAreAlike(String s) {

            //元音
            char[] ch = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
            List<Character> charList = new String(ch).chars()
                    .mapToObj(c -> (char) c)
                    .collect(Collectors.toList());

            int n = s.length() / 2;
            String str1 = s.substring(0, n);
            String str2 = s.substring(n);

            int a = 0;
            int b = 0;
            for (int i = 0; i < str1.length(); i++) {
                char c = str1.charAt(i);
                if (charList.contains(c)) {
                    a++;
                }

                c = str2.charAt(i);
                if (charList.contains(c)) {
                    b++;
                }
            }
            return a == b;

        }
    }
}
